#include "Circle.h"
#include "Rectangle.h"

Circle::Circle(const Point2& pos, const double& radius) : Shape(pos), radius_(radius){}

Circle* Circle::getInstance(const Point2& pos, const double& radius){
    return new Circle(pos, radius);
}

const bool Circle::contains(const Point2& p) const{
    return (getPos() - p).magnitude() < radius_;
}

const bool Circle::overlaps(const Circle* c) const{
    return (getPos() - c->getPos()).magnitude() < radius_ + c->getRadius();
}

const bool Circle::overlaps(const Shape* other) const{
    const std::type_info& ti = typeid(other);
        if (ti == typeid(const Rectangle*))
            return other->overlaps(static_cast<const Shape*>(this));
        else if (ti == typeid(const Circle*))
            return overlaps(dynamic_cast<const Circle*>(other));
        else
            throw std::invalid_argument("Unknown collision shape");
}

double Circle::getArea() const{
    return PI * std::pow(radius_, 2);
}

const Rectangle* Circle::boundingRect() const{
      return Rectangle::getInstance(getPos(), radius_, radius_);
}

Shape* Circle::rotate(const double& angle){
    return this;
}

const double& Circle::getRadius() const{
    return radius_;
}
